package com.acwing.chacter1;

import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * @author anan
 * @create 2021-07-21 19:24
 */
public class Car {
    private static int min(int... is) {
        int min = Integer.MAX_VALUE;
        for (int i : is) {
            if (min > i) {
                min = i;
            }
        }
        return min;
    }

    private static int var(int a ){
        if (a >= 0){
            return a;
        }

        else return -a;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] OnID = new int[K];
        int[] OffID = new int[K];
        int[] startTime = new int[K];
        int[] countZhandian = new int[K];
        int[] duringTime = new int[K];
        int[] endTime = new int[K];
        int end = 0;


        for (int i = 0; i < K; i++) {
            OnID[i] = scanner.nextInt();
            OffID[i] = scanner.nextInt();
            startTime[i] = scanner.nextInt();
            countZhandian[i] = min(var(OffID[i]-OnID[i]), N-var(OffID[i]-OnID[i]));
            duringTime[i] = countZhandian[i] * 5;
            endTime[i] = startTime[i] + duringTime[i];
            if (endTime[i] > end){
                end = endTime[i];
            }
        }


        int count = 0;
        for (int i = 0; i <= end ; i++) {
            int count1 = 0;
            for (int j = 0; j < K; j++) {
                if (startTime[j] <= i && endTime[j] >= i){
                    count1++;
                }
            }
            if (count1 > count){
                count = count1;
            }
        }

        System.out.println(count);


    }
}
